package com.fenghongzhang.day007;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

public class HeadActivity extends AppCompatActivity {
    private ImageView img;
    private Button select;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_head);


        img = (ImageView) findViewById(R.id.img);
        select = (Button) findViewById(R.id.select);


        select.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //1
                //正常
                Intent intent = new Intent(HeadActivity.this, InfoActivity.class);
//        startActivity(intent);
                //要结果
                startActivityForResult(intent,100);

            }
        });

    }

    //6.取返回值

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 100 && resultCode == 101){ //注意值
            int imgId = data.getIntExtra("imgId",0);
            img.setImageResource(imgId);

        }

    }
}
